home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / daten / astrolog / src / calc.c < prev    next >
C/C++ Source or Header  |  1995-08-11  |  22KB  |  749 lines

  1. /*                                                               -*- C -*-
  2. ** Astrolog (Version 4.40) File: calc.c
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1995 by Walter D. Pullen
  6. ** (astara@u.washington.edu). Permission is granted to freely use and
  7. ** distribute these routines provided one doesn't sell, restrict, or
  8. ** profit from them in any way. Modification is allowed provided these
  9. ** notices remain with any altered or edited versions of the program.
  10. **
  11. ** The main planetary calculation routines used in this program have
  12. ** been Copyrighted and the core of this program is basically a
  13. ** conversion to C of the routines created by James Neely as listed in
  14. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  15. ** available from Matrix Software. The copyright gives us permission to
  16. ** use the routines for personal use but not to sell them or profit from
  17. ** them in any way.
  18. **
  19. ** The PostScript code within the core graphics routines are programmed
  20. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  21. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  22. **
  23. ** The extended accurate ephemeris databases and formulas are from the
  24. ** calculation routines in the program "Placalc" and are programmed and
  25. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  26. ** (alois@azur.ch). The use of that source code is subject to
  27. ** regulations made by Astrodienst Zurich, and the code is not in the
  28. ** public domain. This copyright notice must not be changed or removed
  29. ** by any user of this program.
  30. **
  31. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  32. ** X Window graphics initially programmed 10/23-29/1991.
  33. ** PostScript graphics initially programmed 11/29-30/1992.
  34. ** Last code change made 1/29/1995.
  35. */
  36.  
  37. /* $VER: $Id: calc.c,v 1.3 1995/07/02 22:20:25 tf Exp $ */
  38.  
  39. #include "astrolog.h"
  40.  
  41.  
  42. /*
  43. ******************************************************************************
  44. ** House Cusp Calculations.
  45. ******************************************************************************
  46. */
  47.  
  48. /* This is a subprocedure of ComputeInHouses(). Given a zodiac position,  */
  49. /* return which of the twelve houses it falls in. Remember that a special */
  50. /* check has to be done for the house that spans 0 degrees Aries.         */
  51.  
  52. int HousePlaceIn(rDeg)
  53. real rDeg;
  54. {
  55.   int i = 0;
  56.  
  57.   rDeg = Mod(rDeg + 0.5/60.0/60.0);
  58.   do {
  59.     i++;
  60.   } while (!(i >= cSign ||
  61.       (rDeg >= house[i] && rDeg < house[Mod12(i+1)]) ||
  62.       (house[i] > house[Mod12(i+1)] &&
  63.       (rDeg >= house[i] || rDeg < house[Mod12(i+1)]))));
  64.   return i;
  65. }
  66.  
  67.  
  68. /* For each object in the chart, determine what house it belongs in. */
  69.  
  70. void ComputeInHouses()
  71. {
  72.   int i;
  73.  
  74.   for (i = 1; i <= cObj; i++)
  75.     inhouse[i] = HousePlaceIn(planet[i]);
  76. }
  77.  
  78.  
  79. /* This house system is just like the Equal system except that we start */
  80. /* our 12 equal segments from the Midheaven instead of the Ascendant.   */
  81.  
  82. void HouseEqualMidheaven()
  83. {
  84.   int i;
  85.  
  86.   for (i = 1; i <= cSign; i++)
  87.     house[i] = Mod(MC-270.0+30.0*(real)(i-1));
  88. }
  89.  
  90.  
  91. /* This is a new house system similar in philosophy to Porphyry houses.   */
  92. /* Instead of just trisecting the difference in each quadrant, we do a    */
  93. /* smooth sinusoidal distribution of the difference around all the cusps. */
  94.  
  95. void HousePorphyryNeo()
  96. {
  97.   real delta;
  98.   int i;
  99.  
  100.   delta = (MinDistance(MC, Asc) - rDegQuad)/4.0;
  101.  
  102.   house[sLib] = Mod(Asc+rDegHalf); house[sCap] = MC;
  103.   house[sAqu] = Mod(house[sCap] + 30.0 + delta   + is.rSid);
  104.   house[sPis] = Mod(house[sAqu] + 30.0 + delta*2 + is.rSid);
  105.   house[sSag] = Mod(house[sCap] - 30.0 + delta   + is.rSid);
  106.   house[sSco] = Mod(house[sSag] - 30.0 + delta*2 + is.rSid);
  107.  
  108.   for (i = sAri; i < sLib; i++)
  109.     house[i] = Mod(house[i+6]-rDegHalf);
  110. }
  111.  
  112.  
  113. /* The "Whole" house system is like the Equal system with 30 degree houses, */
  114. /* where the 1st house starts at zero degrees of the sign of the Ascendant. */
  115.  
  116. void HouseWhole()
  117. {
  118.   int i;
  119.  
  120.   for (i = 1; i <= cSign; i++)
  121.     house[i] = Mod((SFromZ(Asc)-1)*30+ZFromS(i)+is.rSid);
  122. }
  123.  
  124.  
  125. /* In "null" houses, the cusps are always fixed to start at their cor-    */
  126. /* responding sign, i.e. the 1st house is always at 0 degrees Aries, etc. */
  127.  
  128. void HouseNull()
  129. {
  130.   int i;
  131.  
  132.   for (i = 1; i <= cSign; i++)
  133.     house[i] = Mod(ZFromS(i)+is.rSid);
  134. }
  135.  
  136.  
  137. /* Calculate the house cusp positions, using the specified algorithm. */
  138.  
  139. void ComputeHouses(housesystem)
  140. int housesystem;
  141. {
  142.   char sz[cchSzDef];
  143.  
  144.   if (RAbs(AA) > RFromD(rDegQuad-rAxis) && housesystem < 2) {
  145.     sprintf(sz, "The %s system of houses is not defined at extreme latitudes.", szSystem[housesystem]);
  146.     PrintError(sz);
  147.     Terminate(tcFatal);
  148.   }
  149.  
  150.   switch (housesystem) {
  151.   case  1: HouseKoch();           break;
  152.   case  2: HouseEqual();          break;
  153.   case  3: HouseCampanus();       break;
  154.   case  4: HouseMeridian();       break;
  155.   case  5: HouseRegiomontanus();  break;
  156.   case  6: HousePorphyry();       break;
  157.   case  7: HouseMorinus();        break;
  158.   case  8: HouseTopocentric();    break;
  159.   case  9: HouseEqualMidheaven(); break;
  160.   case 10: HousePorphyryNeo();    break;
  161.   case 11: HouseWhole();          break;
  162.   case 12: HouseNull();           break;
  163.   default: HousePlacidus();
  164.   }
  165. }
  166.  
  167.  
  168. /*
  169. ******************************************************************************
  170. ** Star Position Calculations.
  171. ******************************************************************************
  172. */
  173.  
  174. /* This is used by the chart calculation routine to calculate the positions */
  175. /* of the fixed stars. Since the stars don't move in the sky over time,     */
  176. /* getting their positions is mostly just reading info from an array and    */
  177. /* converting it to the correct reference frame. However, we have to add    */
  178. /* in the correct precession for the tropical zodiac, and sort the final    */
  179. /* index list based on what order the stars are supposed to be printed in.  */
  180.  
  181. void ComputeStars(SD)
  182. real SD;
  183. {
  184.   int i, j;
  185.   real x, y, z;
  186.  
  187.   /* Read in star positions. */
  188.  
  189.   for (i = 1; i <= cStar; i++) 
  190.   {
  191.     x = stardata[i*6-6]; y = stardata[i*6-5]; z = stardata[i*6-4];
  192.     planet[oNorm+i] = RFromD(x*rDegMax/24.0+y*15.0/60.0+z*0.25/60.0);
  193.     x = stardata[i*6-3]; y = stardata[i*6-2]; z = stardata[i*6-1];
  194.     planetalt[oNorm+i] = RFromD(x+y/60.0+z/60.0/60.0);
  195.  
  196.     /* Convert to ecliptic zodiac coordinates. */
  197.  
  198.     EquToEcl(&planet[oNorm+i], &planetalt[oNorm+i]);
  199.     planet[oNorm+i] = Mod(DFromR(planet[oNorm+i])+rEpoch2000+SD);
  200.     planetalt[oNorm+i] = DFromR(planetalt[oNorm+i]);
  201.     ret[oNorm+i] = RFromD(rDegMax/26000.0/365.25);
  202.     starname[i] = i;
  203.   }
  204.  
  205.   /* Sort the index list if -Uz, -Ul, -Un, or -Ub switch in effect. */
  206.  
  207.   if (us.nStar > 1) for (i = 2; i <= cStar; i++) {
  208.     j = i-1;
  209.  
  210.     /* Compare star names for -Un switch. */
  211.  
  212.     if (us.nStar == 'n') while (j > 0 && NCompareSz(
  213.       szObjName[oNorm+starname[j]], szObjName[oNorm+starname[j+1]]) > 0) {
  214.       SwapN(starname[j], starname[j+1]);
  215.       j--;
  216.  
  217.     /* Compare star brightnesses for -Ub switch. */
  218.  
  219.     } else if (us.nStar == 'b') while (j > 0 &&
  220.       starbright[starname[j]] > starbright[starname[j+1]]) {
  221.       SwapN(starname[j], starname[j+1]);
  222.       j--;
  223.  
  224.     /* Compare star zodiac locations for -Uz switch. */
  225.  
  226.     } else if (us.nStar == 'z') while (j > 0 &&
  227.       planet[oNorm+starname[j]] > planet[oNorm+starname[j+1]]) {
  228.       SwapN(starname[j], starname[j+1]);
  229.       j--;
  230.  
  231.     /* Compare star declinations for -Ul switch. */
  232.  
  233.     } else if (us.nStar == 'l') while (j > 0 &&
  234.       planetalt[oNorm+starname[j]] < planetalt[oNorm+starname[j+1]]) {
  235.       SwapN(starname[j], starname[j+1]);
  236.       j--;
  237.     }
  238.   }
  239. }
  240.  
  241.  
  242. /*
  243. ******************************************************************************
  244. ** Chart Calculation.
  245. ******************************************************************************
  246. */
  247.  
  248. /* Given a zodiac degree, transform it into its Decan sign, where each    */
  249. /* sign is trisected into the three signs of its element. For example,    */
  250. /* 1 Aries -> 3 Aries, 10 Leo -> 0 Sagittarius, 25 Sagittarius -> 15 Leo. */
  251.  
  252. real Decan(deg)
  253. real deg;
  254. {
  255.   int sign;
  256.   real unit;
  257.  
  258.   sign = SFromZ(deg);
  259.   unit = deg - ZFromS(sign);
  260.   sign = Mod12(sign + 4*((int)RFloor(unit/10.0)));
  261.   unit = (unit - RFloor(unit/10.0)*10.0)*3.0;
  262.   return ZFromS(sign)+unit;
  263. }
  264.  
  265.  
  266. /* Transform spherical to rectangular coordinates in x, y, z. */
  267.  
  268. void SphToRec(r, azi, alt, rx, ry, rz)
  269. real r, azi, alt, *rx, *ry, *rz;
  270. {
  271.   real rT;
  272.  
  273.   *rz = r *RSinD(alt);
  274.   rT  = r *RCosD(alt);
  275.   *rx = rT*RCosD(azi);
  276.   *ry = rT*RSinD(azi);
  277. }
  278.  
  279.  
  280. #ifdef PLACALC
  281. /* Compute the positions of the planets at a certain time using the Placalc */
  282. /* accurate formulas and ephemeris. This will superseed the Matrix routine  */
  283. /* values and is only called with the -b switch is in effect. Not all       */
  284. /* objects or modes are available using this, but some additional values    */
  285. /* such as Moon and Node velocities not available without -b are. (This is  */
  286. /* the one place in Astrolog which calls the Placalc package functions.)    */
  287.  
  288. void ComputePlacalc(t)
  289. real t;
  290. {
  291.   int i;
  292.   real r1, r2, r3, r4;
  293.  
  294.   /* We can compute the positions of Sun through Pluto, Chiron, and the  */
  295.   /* North Node using Placalc. The other objects must be done elsewhere. */
  296.  
  297.   for (i = oSun; i <= oLil; i++) {
  298.     if ((i > oChi && i < oNod) || (ignore[i] && i > oMoo))
  299.       continue;
  300.     if (FPlacalcPlanet(i, t*36525.0+2415020.0, us.objCenter != oSun,
  301.       &r1, &r2, &r3, &r4)) {
  302.  
  303.       /* Note that this can't compute charts with central planets other */
  304.       /* than the Sun or Earth or relative velocities in current state. */
  305.  
  306.       planet[i]    = Mod(r1 + is.rSid);
  307.       planetalt[i] = r2;
  308.       ret[i]       = RFromD(r3);
  309.  
  310.       /* Compute x,y,z coordinates from azimuth, altitude, and distance. */
  311.  
  312.       SphToRec(r4, planet[i], planetalt[i],
  313.         &spacex[i], &spacey[i], &spacez[i]);
  314.     }
  315.   }
  316. }
  317. #endif
  318.  
  319.  
  320. /* This is probably the main routine in all of Astrolog. It generates a   */
  321. /* chart, calculating the positions of all the celestial bodies and house */
  322. /* cusps, based on the current chart information, and saves them for use  */
  323. /* by any of the display routines.                                        */
  324.  
  325. real CastChart(fDate)
  326. bool fDate;
  327. {
  328.   CI ci;
  329.   real housetemp[cSign+1], Off = 0.0, vtx, j;
  330.   int i, k;
  331.  
  332.   /* Hack: Time zone +/-24 means to have the time of day be in Local Mean */
  333.   /* Time (LMT). This is done by making the time zone value reflect the   */
  334.   /* logical offset from GMT as indicated by the chart's longitude value. */
  335.  
  336.   if (RAbs(ZZ) == 24.0)
  337.     ZZ = DecToDeg(OO)/15.0;
  338.  
  339.   ci = ciCore;
  340.  
  341.   if (MM == -1)
  342.   {
  343.     /* Hack: If month is negative, then we know chart was read in through a  */
  344.     /* -o0 position file, so the planet positions are already in the arrays. */
  345.  
  346.     MC = planet[oMC]; Asc = planet[oAsc];
  347.   } 
  348.   else 
  349.   {
  350.  
  351.     for (i = 1; i <= cObj; i++)
  352.     {
  353.       planet[i] = planetalt[i] = 0.0;    /* On ecliptic unless we say so.  */
  354.       ret[i] = 1.0;                      /* Direct until we say otherwise. */
  355.     }
  356.  
  357.     Off = ProcessInput(fDate);
  358.     ComputeVariables(&vtx);
  359.  
  360.     if (us.fGeodetic)               /* Check for -G geodetic chart. */
  361.       RA = RFromD(Mod(-OO));
  362.  
  363.     MC  = CuspMidheaven();          /* Calculate our Ascendant & Midheaven. */
  364.     Asc = CuspAscendant();
  365.  
  366.     ComputeHouses(us.nHouseSystem); /* Go calculate house cusps. */
  367.  
  368.     /* Go calculate planet, Moon, and North Node positions. */
  369.  
  370.     ComputePlanets();
  371.     if (!ignore[oMoo] || !ignore[oNod] || !ignore[oSou] || !ignore[oFor]) 
  372.     {
  373.       ComputeLunar(&planet[oMoo], &planetalt[oMoo],
  374.         &planet[oNod], &planetalt[oNod]);
  375.       ret[oNod] = -1.0;
  376.     }
  377.  
  378.     /* Compute more accurate ephemeris positions for certain objects. */
  379.  
  380. #ifdef PLACALC
  381.     if (us.fPlacalc)
  382.       ComputePlacalc(T);
  383. #endif
  384.     if (!us.fPlacalc) 
  385.     {
  386.       planet[oSou] = Mod(planet[oNod]+rDegHalf);
  387.       ret[oSou] = ret[oNod] = RFromD(-0.053);
  388.       ret[oMoo] = RFromD(12.5);
  389.     }
  390.  
  391.     /* Calculate position of Part of Fortune. */
  392.  
  393.     j = planet[oMoo]-planet[oSun];
  394.  
  395.     if (us.nArabicNight < 0)
  396.       neg(j);
  397.  
  398.     j = RAbs(j) < rDegQuad ? j : j - RSgn(j)*rDegMax;
  399.     planet[oFor] = Mod(j+Asc);
  400.  
  401.     /* Fill in "planet" positions corresponding to house cusps. */
  402.  
  403.     planet[oVtx] = vtx; planet[oEP] = CuspEastPoint();
  404.  
  405.     for (i = 2; i <= cSign; i++)
  406.       planet[cuspLo + i - 1] = house[i];
  407.  
  408.     planet[oAsc] = Asc; planet[oMC] = MC;
  409.     planet[oDes] = Mod(Asc + rDegHalf); planet[oNad] = Mod(MC + rDegHalf);
  410.  
  411.     for (i = oFor; i <= cuspHi; i++)
  412.       ret[i] = RFromD(rDegMax);
  413.   }
  414.  
  415.   /* Go calculate star positions if -U switch in effect. */
  416.  
  417.   if (us.nStar)
  418.     ComputeStars(us.fSiderial ? 0.0 : -Off);
  419.  
  420.   /* Transform ecliptic to equatorial coordinates if -sr in effect. */
  421.  
  422.   if (us.fEquator)
  423.     for (i = 1; i <= cObj; i++) if (!ignore[i]) 
  424.     {
  425.       planet[i]    = RFromD(Tropical(planet[i]));
  426.       planetalt[i] = RFromD(planetalt[i]);
  427.       EclToEqu(&planet[i], &planetalt[i]);
  428.       planet[i]    = DFromR(planet[i]);
  429.       planetalt[i] = DFromR(planetalt[i]);
  430.     }
  431.  
  432.   /* Now, we may have to modify the base positions we calculated above based */
  433.   /* on what type of chart we are generating.                                */
  434.  
  435.   if (us.fProgress && us.fSolarArc) /* Are we doing a -p0 solar arc chart? */
  436.   {
  437.     for (i = 1; i <= cObj; i++)
  438.       planet[i] = Mod(planet[i] + (is.JDp - is.JD) / us.rProgDay);
  439.     for (i = 1; i <= cSign; i++)
  440.       house[i]  = Mod(house[i]  + (is.JDp - is.JD) / us.rProgDay);
  441.   }
  442.  
  443.   if (us.nHarmonic > 1)             /* Are we doing a -x harmonic chart?     */
  444.     for (i = 1; i <= cObj; i++)
  445.       planet[i] = Mod(planet[i] * (real)us.nHarmonic);
  446.  
  447.   if (us.objOnAsc) 
  448.   {
  449.     if (us.objOnAsc > 0)            /* Is -1 put on Ascendant in effect?     */
  450.       j = planet[us.objOnAsc]-Asc;
  451.     else                            /* Or -2 put object on Midheaven switch? */
  452.       j = planet[-us.objOnAsc]-MC;
  453.     for (i = 1; i <= cSign; i++)    /* If so, rotate the houses accordingly. */
  454.       house[i] = Mod(house[i]+j);
  455.   }
  456.  
  457.   /* Check to see if we are -F forcing any objects to be particular values. */
  458.  
  459.   for (i = 1; i <= cObj; i++)
  460.   {
  461.     if (force[i] != 0.0)
  462.     {
  463.       planet[i] = force[i]-rDegMax;
  464.       planetalt[i] = ret[i] = 0.0;
  465.     }
  466.   }
  467.  
  468.   ComputeInHouses();        /* Figure out what house everything falls in. */
  469.  
  470.   /* If -f domal chart switch in effect, switch planet and house positions. */
  471.  
  472.   if (us.fFlip)
  473.   {
  474.     for (i = 1; i <= cObj; i++)
  475.     {
  476.       k = inhouse[i];
  477.       inhouse[i] = SFromZ(planet[i]);
  478.       planet[i] = ZFromS(k)+MinDistance(house[k], planet[i]) /
  479.         MinDistance(house[k], house[Mod12(k+1)])*30.0;
  480.     }
  481.  
  482.     for (i = 1; i <= cSign; i++)
  483.     {
  484.       k = HousePlaceIn(ZFromS(i));
  485.       housetemp[i] = ZFromS(k)+MinDistance(house[k], ZFromS(i)) /
  486.         MinDistance(house[k], house[Mod12(k+1)])*30.0;
  487.     }
  488.  
  489.     for (i = 1; i <= cSign; i++)
  490.       house[i] = housetemp[i];
  491.   }
  492.  
  493.   /* If -3 decan chart switch in effect, edit planet positions accordingly. */
  494.  
  495.   if (us.fDecan)
  496.   {
  497.     for (i = 1; i <= cObj; i++)
  498.       planet[i] = Decan(planet[i]);
  499.     ComputeInHouses();
  500.   }
  501.  
  502.   ciCore = ci;
  503.   return T;
  504. }
  505.  
  506.  
  507. /*
  508. ******************************************************************************
  509. ** Aspect Calculations.
  510. ******************************************************************************
  511. */
  512.  
  513. /* Set up the aspect/midpoint grid. Allocate memory for this array, if not */
  514. /* already done. Allocation is only done once, first time this is called.  */
  515.  
  516. bool FEnsureGrid()
  517. {
  518.   if (grid != NULL)
  519.     return fTrue;
  520.  
  521.   grid = (GridInfo FAR *)PAllocate(sizeof(GridInfo), fFalse, "grid");
  522.   return grid != NULL;
  523. }
  524.  
  525.  
  526. /* Indicate whether some aspect between two objects should be shown. */
  527.  
  528. bool FAcceptAspect(obj1, asp, obj2)
  529. int obj1, asp, obj2;
  530. {
  531.   int fSupp;
  532.  
  533.   if (ignorea(asp))    /* If the aspect restricted, reject immediately. */
  534.     return fFalse;
  535.  
  536.   if (us.fSmartCusp)
  537.   {
  538.     /* Allow only conjunctions to the minor house cusps. */
  539.  
  540.     if ((FMinor(obj1) || FMinor(obj2)) && asp > aCon)
  541.       return fFalse;
  542.  
  543.     /* Prevent any simultaneous aspects to opposing angle cusps,     */
  544.     /* e.g. if conjunct one, don't be opposite the other; if trine   */
  545.     /* one, don't sextile the other; don't square both at once, etc. */
  546.  
  547.     fSupp = (asp == aOpp || asp == aSex || asp == aSSx || asp == aSes);
  548.     if ((FAngle(obj1) || FAngle(obj2)) &&
  549.       (fSupp || (asp == aSqu &&
  550.       (obj1 == oDes || obj2 == oDes || obj1 == oNad || obj2 == oNad))))
  551.       return fFalse;
  552.  
  553.     /* Prevent any simultaneous aspects to the North and South Node. */
  554.  
  555.     if (fSouthNode)
  556.     {
  557.       if (((obj1 == oNod || obj2 == oNod) && fSupp) ||
  558.           ((obj1 == oSou || obj2 == oSou) && (fSupp || asp == aSqu)))
  559.         return fFalse;
  560.     }
  561.   }
  562.   return fTrue;
  563. }
  564.  
  565.  
  566. /* This is a subprocedure of FCreateGrid() and FCreateGridRelation().   */
  567. /* Given two planets, determine what aspect, if any, is present between */
  568. /* them, and save the aspect name and orb in the specified grid cell.   */
  569.  
  570. void GetAspect(planet1, planet2, ret1, ret2, i, j)
  571. real *planet1, *planet2, *ret1, *ret2;
  572. int i, j;
  573. {
  574.   int k;
  575.   real l, m;
  576.  
  577.   grid->v[i][j] = grid->n[i][j] = 0;
  578.   l = MinDistance(planet2[i], planet1[j]);
  579.   for (k = us.nAsp; k >= 1; k--)
  580.   {
  581.     if (!FAcceptAspect(i, k, j))
  582.       continue;
  583.  
  584.     m = l-aspectangle[k];
  585.     if (RAbs(m) < GetOrb(i, j, k))
  586.     {
  587.       grid->n[i][j] = k;
  588.  
  589.       /* If -ga switch in effect, then change the sign of the orb to    */
  590.       /* correspond to whether the aspect is applying or separating.    */
  591.       /* To do this, we check the velocity vectors to see if the        */
  592.       /* planets are moving toward, away, or are overtaking each other. */
  593.  
  594.       if (us.fAppSep)
  595.         m = RSgn2(ret1[j]-ret2[i]) * RSgn2(MinDifference(planet2[i], planet1[j]))*RSgn2(m)*RAbs(m);
  596.       grid->v[i][j] = (int)(m*60.0);
  597.     }
  598.   }
  599. }
  600.  
  601.  
  602. /* Very similar to GetAspect(), this determines if there is a parallel or */
  603. /* contraparallel aspect between the given two planets, and stores the    */
  604. /* result as above. The settings and orbs for conjunction are used for    */
  605. /* parallel and those for opposition are used for contraparallel.         */
  606.  
  607. void GetParallel(planet1, planet2, planetalt1, planetalt2, i, j)
  608. real *planet1, *planet2, *planetalt1, *planetalt2;
  609. int i, j;
  610. {
  611.   int k;
  612.   real l, alt1, alt2;
  613.  
  614.   l = RFromD(planet1[j]); alt1 = RFromD(planetalt1[j]);
  615.   EclToEqu(&l, &alt1); alt1 = DFromR(alt1);
  616.   l = RFromD(planet2[i]); alt2 = RFromD(planetalt2[i]);
  617.   EclToEqu(&l, &alt2); alt2 = DFromR(alt2);
  618.   grid->v[i][j] = grid->n[i][j] = 0;
  619.  
  620.   for (k = Min(us.nAsp, aOpp); k >= 1; k--)
  621.   {
  622.     if (!FAcceptAspect(i, k, j))
  623.       continue;
  624.  
  625.     l = RAbs(k == aCon ? alt1 - alt2 : RAbs(alt1) - RAbs(alt2));
  626.  
  627.     if (l < GetOrb(i, j, k))
  628.     {
  629.       grid->n[i][j] = k;
  630.       grid->v[i][j] = (int)(l*60.0);
  631.     }
  632.   }
  633. }
  634.  
  635.  
  636. /* Fill in the aspect grid based on the aspects taking place among the */
  637. /* planets in the present chart. Also fill in the midpoint grid.       */
  638.  
  639. bool FCreateGrid(fFlip)
  640. bool fFlip;
  641. {
  642.   int i, j, k;
  643.   real l;
  644.  
  645.   if (!FEnsureGrid())
  646.     return fFalse;
  647.  
  648.   for (j = 1; j <= cObj; j++) if (!ignore[j])
  649.   {
  650.     for (i = 1; i <= cObj; i++) if (!ignore[i])
  651.     {
  652.       /* The parameter 'flip' determines what half of the grid is filled in */
  653.       /* with the aspects and what half is filled in with the midpoints.    */
  654.  
  655.       if (fFlip ? i > j : i < j) {
  656.         if (us.fParallel)
  657.           GetParallel(planet, planet, planetalt, planetalt, i, j);
  658.         else
  659.           GetAspect(planet, planet, ret, ret, i, j);
  660.       } else if (fFlip ? i < j : i > j) {
  661.         l = Mod(Midpoint(planet[i], planet[j])); k = (int)l;  /* Calculate */
  662.         grid->n[i][j] = k/30+1;                               /* midpoint. */
  663.         grid->v[i][j] = (int)((l-(real)(k/30)*30.0)*60.0);
  664.       } else {
  665.         grid->n[i][j] = SFromZ(planet[j]);
  666.         grid->v[i][j] = (int)(planet[j]-(real)(grid->n[i][j]-1)*30.0);
  667.       }
  668.     }
  669.   }
  670.   return fTrue;
  671. }
  672.  
  673.  
  674. /* This is similar to the previous function; however, this time fill in the */
  675. /* grid based on the aspects (or midpoints if 'acc' set) taking place among */
  676. /* the planets in two different charts, as in the -g -r0 combination.       */
  677.  
  678. bool FCreateGridRelation(fMidpoint)
  679. bool fMidpoint;
  680. {
  681.   int i, j, k;
  682.   real l;
  683.  
  684.   if (!FEnsureGrid())
  685.     return fFalse;
  686.  
  687.   for (j = 1; j <= cObj; j++) if (!ignore[j])
  688.   {
  689.     for (i = 1; i <= cObj; i++) if (!ignore[i])
  690.     {
  691.       if (!fMidpoint) 
  692.       {
  693.         if (us.fParallel)
  694.           GetParallel(cp1.obj, cp2.obj, cp1.alt, cp2.alt, i, j);
  695.         else
  696.           GetAspect(cp1.obj, cp2.obj, cp1.dir, cp2.dir, i, j);
  697.       }
  698.       else
  699.       {
  700.         l = Mod(Midpoint(cp2.obj[i], cp1.obj[j])); k = (int)l; /* Calculate */
  701.         grid->n[i][j] = k/30+1;                                /* midpoint. */
  702.         grid->v[i][j] = (int)((l-(real)(k/30)*30.0)*60.0);
  703.       }
  704.     }
  705.   }
  706.   return fTrue;
  707. }
  708.  
  709.  
  710. /* Fill out tables based on the number of unrestricted planets in signs by  */
  711. /* element, signs by mode, as well as other values such as the number of    */
  712. /* objects in yang vs. yin signs, in various house hemispheres (north/south */
  713. /* and east/west), and the number in first six signs vs. second six signs.  */
  714. /* This is used by the -v chart listing and the sidebar in graphics charts. */
  715.  
  716. void CreateElemTable(pet)
  717. ET *pet;
  718. {
  719.   int i, s;
  720.  
  721.   ClearB((lpbyte)pet, (int)sizeof(ET));
  722.   for (i = 1; i <= cObj; i++) if (!ignore[i]) 
  723.   {
  724.     pet->coSum++;
  725.     s = SFromZ(planet[i]);
  726.     pet->coSign[s-1]++;
  727.     pet->coElemMode[(s-1)&3][(s-1)%3]++;
  728.     pet->coElem[(s-1)&3]++; pet->coMode[(s-1)%3]++;
  729.     pet->coYang += (s & 1);
  730.     pet->coLearn += (s < sLib);
  731.  
  732.     if (!FCusp(i))
  733.     {
  734.       pet->coHemi++;
  735.       s = inhouse[i];
  736.       pet->coHouse[s-1]++;
  737.       pet->coModeH[(s-1)%3]++;
  738.       pet->coMC += (s >= sLib);
  739.       pet->coAsc += (s < sCan || s >= sCap);
  740.     }
  741.   }
  742.   pet->coYin   = pet->coSum  - pet->coYang;
  743.   pet->coShare = pet->coSum  - pet->coLearn;
  744.   pet->coDes   = pet->coHemi - pet->coAsc;
  745.   pet->coIC    = pet->coHemi - pet->coMC;
  746. }
  747.  
  748. /* calc.c */
  749.